package com.example.zbh.dsliao.ui.activty;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import android.widget.TextView;
import android.widget.Toast;

import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMChatOptions;
import com.easemob.chat.EMContactManager;
import com.easemob.exceptions.EaseMobException;
import com.example.zbh.dsliao.R;

/**
 * Created by zbh on 15/11/21.
 */
public class AddContactActivity extends BaseActivity implements View.OnClickListener {
    private EditText edit_note;//用户名
    private TextView name;
    private Button indicator;
    private Button search;
    private String findName = null;
    private LinearLayout ll_user, back;

    @Override
    protected int getLayOut() {
        return R.layout.dl_activity_add_contact;
    }

    @Override
    protected void initView() {
        edit_note = findeView(R.id.edit_note);
        name = findeView(R.id.name);
        indicator = findeView(R.id.indicator);
        search = findeView(R.id.search);
        ll_user = findeView(R.id.ll_user);
        back = findeView(R.id.back);



    }

    @Override
    protected void initData() {
        search.setOnClickListener(this);
        indicator.setOnClickListener(this);
        back.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.search:
                findFriend();
                break;
            case R.id.indicator:
                addFriend();
                break;
            case R.id.back:
                finish();
                break;
        }
    }

    private void addFriend() {
        try {
            EMContactManager.getInstance().addContact(findName, "ssss");
            Toast.makeText(this,"发送请求成功,等待对方验证", Toast.LENGTH_SHORT).show();
        } catch (EaseMobException e) {
            e.printStackTrace();
        }
    }

    private void findFriend() {
        ll_user.setVisibility(View.VISIBLE);
        findName = edit_note.getText().toString();
        name.setText(findName);
    }
}
